package com.clkj.zhonghui.controller.system;

import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.pojo.system.Rule;
import com.clkj.zhonghui.service.system.RuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yawang
 * @create 2024/07/17 14:21:45
 **/
@RestController
@RequestMapping(value = "/Rule")
@CrossOrigin
@Api(value = "/Rule", tags = {"中汇Rule"})
public class RuleController {

    @Autowired
    private RuleService ruleService;
    @PostMapping("/addRule")
    @ApiOperation(value = "添加修改规则")
    public Result addRule(Rule rule){
        try {
            ruleService.addRule(rule);
            return new Result(true, StatusCode.OK, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "添加失败");
        }
    }

    @PostMapping("/getRuleList")
    @ApiOperation(value = "获取规则列表")
    public Result getRuleList(){

        try {
            List<Rule> list = ruleService.getRuleList();
            return new Result(true, StatusCode.OK, "获取成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "获取失败");
        }
    }
}
